
******SOCIAL MOBILIAZATION OUTCOMES (TABLE 3; TABLE C.2 PANEL B; TABLE C.3 COL 2)********

set more off
clear all 
clear matrix
capture log close

adopath + "$main/DoFiles"																		


local seed = 999
local reps = 5000



//--> DATA: SOCIAL MOBILIZATION OUTCOMES

		use "$data/social_fa_vars.dta", clear
	
//--> DATA: FA TREATMENT STATUS 

		sort fw_code
		merge fw_code using "$data/FWHR.dta"
		drop _m

//--> DATA: BASELINE VARS

		preserve
			use "$data/baseline_fa_vars.dta", clear
			local credit_var weighted_num_active_loan weighted_num_new_loan weighted_amount_issue wmiss_pay_maturity_month inv_ratio_miss_pay_month inv_ratio_miss_pay_20
			foreach v in `credit_var' {
				rename `v' `v'0
				}
			sort fw_code
			tempfile temp
			save `temp'
		restore
		
		sort fw_code
		merge fw_code using `temp', nok
		drop _m
	
		//--> REGION DUMMIES
				tab region, gen(r)
				
		//--> SELECTION INTO VERFIED MPRS
		
				g audit = 1 if stdsocial_index!=.
				replace audit = 0 if audit==.

//--> OUTPUT: TABLE 3 (SOCIAL OUTCOMES: TRIGGERS AND INDEX)	
	*********************************************************************************************************************************************************
	
		local social_var weighted_num_new_co saver_per_mem attendance_per_mem stdsocial_index

	
		//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
	
			reg audit r1 r2 r3 treat_credit treat_sm
			sum audit if treat==0
			local m = r(mean)
			outreg2 using "$output/table3 (coeff).xls", replace addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
			local replace
			foreach v in `social_var'{
				reg `v' r1 r2 r3 treat_credit treat_sm if audit==1
				sum `v' if treat==0 & audit==1
				local m = r(mean)
				outreg2 using "$output/table3 (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				local replace
				}
				
				
				
		log using "$output/table3 (p-values)", replace	
		
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					cgmwildboot audit r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					foreach v in `social_var' {
						cgmwildboot `v' r1 r2 r3 treat_credit treat_sm if audit==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
						}
					
							
			//--> CREDIT VS. SOCIAL
			
					g x1 = treat_credit + treat_sm
					g test1 = treat_credit //RELEVANT VAR FOR F TEST
						
					cgmwildboot audit r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					foreach v in `social_var' {
						cgmwildboot `v' r1 r2 r3 x1 test1 if audit==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
						}
					

		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
					randcmd((treat_credit treat_sm) reg audit treat_credit treat_sm r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
					foreach v in `social_var' {
						randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm r1 r2 r3 if audit==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						}
							
			//--> CREDIT VS. SOCIAL (F TEST)
					
					randcmd((treat_credit) reg audit treat_credit x1 r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
					foreach v in `social_var' {
						randcmd((treat_credit) reg `v' treat_credit x1 r1 r2 r3 if audit==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						}
			
	log close
	*********************************************************************************************************************************************************
	
	
	
//--> OUTPUT: ONLINE APPENDIX TABLE C.2	(SOCIAL OUTCOMES: ALL COMPONENTS OF INDEX)
	*********************************************************************************************************************************************************
	
	keep if audit==1
	drop x1
	drop test1
	
	
	//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
			
			local social_var weighted_num_new_co saver_per_mem attendance_per_mem weighted_alive_dead_co savings_per_co other_meet_per_co training_per_co
			local replace  replace 
			
			foreach v in `social_var'{
				reg `v' r1 r2 r3 treat_credit treat_sm
				sum `v' if treat==0
				local m = r(mean)
				outreg2 using "$output/tableC_2B (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				local replace
				}
				
		log using "$output/tableC_2B (p-values)", replace	

				
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					foreach v in `social_var'{
						cgmwildboot `v' r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
						}
					
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
					g x1 = treat_credit + treat_sm
					g test1 = treat_credit //RELEVANT VAR FOR F TEST
						
					foreach v in `social_var'{
						cgmwildboot `v' r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
						}
				

		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
					foreach v in `social_var' {
						randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						}
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
					foreach v in `social_var' {
						randcmd((treat_credit) reg `v' treat_credit x1 r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						}
			
	log close
	*********************************************************************************************************************************************************

	

//--> OUTPUT: ONLINE APPENDIX TABLE C.3; COL 2 (SOCIAL OUTCOME: INDEX w/ FULL CONTROLS)	
	*********************************************************************************************************************************************************
	
	drop x1
	drop test1
	


	local add_control age female marital_status head_hh education consumption_hh work_month nfirst_job work_vb weighted_num_co_alive  still_work_nrsp_2years overtime_perday credit_bonus soc_help_credit volunteer_before_nrsp job_like_help
	local pre_mis_control weighted_num_active_loan0 inv_ratio_miss_pay_200 weighted_num_new_loan0 weighted_amount_issue0 inv_ratio_miss_pay_month0 wmiss_pay_maturity_month0 minv_ratio_miss_pay_20
	
	//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
		
			
				reg stdsocial_index `add_control' `pre_mis_control' r1 r2 r3 treat_credit treat_sm
				sum stdsocial_index if treat==0
				local m = r(mean)
				outreg2 using "$output/tableC_3_col2 (coeff).xls", replace addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				
				
		
				
		log using "$output/tableC_3_col2 (p-values)", replace	

				
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					cgmwildboot stdsocial_index `add_control' `pre_mis_control' r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
					
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
					g x1 = treat_credit + treat_sm
					g test1 = treat_credit //RELEVANT VAR FOR F TEST
						
					cgmwildboot stdsocial_index `add_control' `pre_mis_control' r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed') 
									

		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
						randcmd((treat_credit treat_sm) reg stdsocial_index treat_credit treat_sm `add_control' `pre_mis_control' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						
							
			//--> CREDIT VS. SOCIAL (F TEST)
			
						randcmd((treat_credit) reg stdsocial_index treat_credit x1 `add_control' `pre_mis_control' r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						
			
	log close
	*********************************************************************************************************************************************************
		
	
